
/**
 * 定义路由： Router.[method](path, (request, response) => { })
 *    Router: 路由实例
 *    app.method(path, (request, response) => { })
 */
// 使用 multer 处理文件上传
const multer = require("multer");
const { v4: uuid } = require("uuid");
const path = require("path");
// 配置上传文件的存储位置和文件名
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, "./public/avatars");
    },
    filename: function (req, file, cb) {
        const ext = path.extname(file.originalname);
        cb(null, uuid() + ext);
    },
});
const upload = multer({ storage });

const { db } = require("../database");

const { validate, validators } = require("../validate");

// 导入加密函数
const { makePassword, checkPassword } = require("../utils");
// jwt
const { sign } = require("../jwt");
const multiAvatar = require("@multiavatar/multiavatar");

const router = require("express").Router();
const { useAuthorization } = require("./base");
router.use(useAuthorization); //You，13小时前。用户


//获取转正信息
router.get('/',
    async (req, res) => {
        const examine = await db.select('select * from examine')
        res.send(
            {
                code: 200,
                message: "获取模块信息成功",
                result: examine,
            }
        )
    })
    //审批转正
    .put('/',
        async (req, res) => {
            const { id, person, reason, createtime, status } = req.body;

            const userid = req.user.id
            // console.log(userid);
            const username = await db.select('select * from user where id=?', [userid])
            // console.log(username);
            await db.run`update examine set person = ${person}, reason = ${reason}, createtime = ${createtime},status = ${status}, processedBy = ${username[0].username} where id=${id}`
            // console.log(username[0].username);
            const meets = await db.findOne`select * from examine where id = ${id}`;
            res.send({
                code: 200,
                message: "转正修改成功",
                result: meets
            });
            
        })


const registerRouter = (app) => app.use("/examine", router);
module.exports = { registerRouter };